package 机器人跳跃问题;

import java.util.Scanner;

public class Main {
    static int N = 100010, n;
    static int[] h = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            h[i] = in.nextInt();
        }
        int l = 1, r = 100000;
        while (l < r) {
            int mid = l + r >> 1;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        System.out.println(l);
    }

    private static boolean check(int E) {
        for (int i = 1; i <= n; i++) {
            E = 2 * E - h[i];
            if (E < 0) {
                return false;
            }
            if (E >= 1e5) {
                return true;
            }
        }
        return true;
    }
}
